package zdh.jfinabbsapp.api;

import org.json.JSONException;
import org.json.JSONObject;
import org.kymjs.kjframe.utils.KJLoger;

import zdh.jfinabbsapp.api.dao.User;

/**
 * 作者：zdh1000
 * 创建时间： 2015/7/7 21:02
 * 邮箱：wdzdh1000@163.com
 */
public class UserAPI {

    public static String getUserUrl() {
        return API.ROOT + "/user";
    }

    ///api/user
    public static User getUserByToken(String json) {
        User user = new User();
        try {
            KJLoger.debug(UserAPI.class.getName() + " : " + json);
            JSONObject jsonObject = new JSONObject(json);
            JSONObject detail = jsonObject.getJSONObject("detail");
            user.setGender(detail.getString("gender"));
            user.setOpenId(detail.getString("open_id"));
            user.setSignature(detail.getString("signature"));
            user.setExpireTime(detail.getString("expire_time"));
            user.setAvatar(detail.getString("avatar"));
            user.setUrl(detail.getString("url"));
            user.setToken(detail.getString("token"));
            user.setScore(detail.getInt("score"));
            user.setMission(detail.getString("mission"));
            user.setPassword(detail.getString("password"));
            user.setInTime(detail.getString("in_time"));
            user.setNickname(detail.getString("nickname"));
            user.setId(detail.getString("id"));
            user.setThirdloginType(detail.getString("thirdlogin_type"));
            user.setEmail(detail.getString("email"));
        } catch (JSONException e) {
            KJLoger.debug(UserAPI.class.getName() + " : " + e.getMessage());
        }
        return user;
    }

    public static String doToken(String token)
    {
        String temp = token;
        int l = token.indexOf("@");
        if(l==-1)
            return token;
        temp = token.substring(0,l);
        return temp;
    }
}
